<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>登录</title>
	<!-- 样 式 文 件 -->
	<link rel="stylesheet" href="/component/pear/css/pear.css" />
	<link rel="stylesheet" href="/admin/css/other/login.css" />
	<style>
		.index-txt {
			margin-top: 10px;
			line-height: 18px;
			color: #5f5f5f;
			text-align: right;
		}
	
		.index-txt>a {
			color: #5FB878;
		}
	
		.logo1 {
			width: 180px !important;
		}
	</style>
</head>
<!-- 代 码 结 构 -->

<body background="/admin/images/background.svg" style="background-size: cover;">
	<form class="layui-form" action="javascript:void(0);">
		<div class="layui-form-item" style="text-align: center;">
			<img class="logo1" src="/static/img/logo3.png" />
			<div class="desc">
				让 个 人 收 款 更 加 轻 松 便 捷
			</div>
		</div>
		<div class="layui-form-item">
			<input type="text" name="username" placeholder="账 户" lay-verify="required" hover class="layui-input" />
		</div>
		<div class="layui-form-item">
			<input type="password" name="password" placeholder="密 码" lay-verify="required" hover class="layui-input" />
		</div>
		<div class="layui-form-item layui-row">
			<div class="layui-col-xs6"><input name="keep_login" type="checkbox" title="记住密码" lay-skin="primary" checked>
			</div>
			<div class="layui-col-xs6">
				<div class="index-txt"><a href="/">首 页</a></div>
			</div>
		</div>
		<div class="layui-form-item">
			<button type="submit" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
				登 入
			</button>
		</div>
	</form>
	<!-- 资 源 引 入 -->
	<script src="/component/layui/layui.js"></script>
	<script src="/component/pear/pear.js"></script>
	<script>
		layui.use(['form', 'button', 'popup'], function () {
			var form = layui.form;
			var button = layui.button;
			var popup = layui.popup;

			// 登 录 提 交
			form.on('submit(login)', function (data) {
				let field = data.field;
				const is_keep = 'keep_login' in field;
				if (!is_keep) {
					field.keep_login = 'off';
				}
				// 动画
				const act_btn = button.load({ elem: '.login' });
				// 登陆
				(async () => {
					const rep_login = await fetch('/api/user/login', { method: 'post', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(field) });
					if (rep_login.status !== 200) {
						popup.failure('请求失败，请重试！');
						act_btn.stop();
						return false;
					}
					const info = await rep_login.json();
					if (info.code === 0) {
						act_btn.stop();
						popup.success("登录成功", function () {
							location.href = "/Console/index"
						});
					} else {
						act_btn.stop();
						popup.failure(info.msg);
					}

				})();
				return false;
			});
		})
	</script>
</body>

</html>